﻿using System;
using System.Collections.Generic;

namespace Bilibili.Model.Common
{
    public sealed class ReturnPlayModel
    {
        public bool Success { get; set; }
        public string Message { get; set; }
        public string DamakuXml { get; set; }
        public dynamic MediaSources { get; set; }
        public SourceMode SourceMode { get; set; }
        public IEnumerable<string> Urls { get; set; }
        public DataSourceHeader Headers { get; set; }
        public (string Height, string Width) VideoSize { get; set; }
        public (double Height, double Width) GetRange(double height, double width)
        {
            double VideoHeight = double.TryParse(VideoSize.Height, out double h) ? h : Convert.ToDouble(height),
                    VideoWidth = double.TryParse(VideoSize.Width, out double w) ? w : Convert.ToDouble(width);
            return (VideoHeight, VideoWidth);
        }
        public int FontSize
        {
            get
            {
                try
                {
                    var temp = GetRange(0, 0);
                    if(temp.Height > temp.Width)
                    {
                        if (temp.Width <= 360)
                            return 24;
                        else if (temp.Width > 360 && temp.Width <= 480)
                            return 32;
                        else if (temp.Width > 480 && temp.Width <= 720)
                            return 48;
                        else if (temp.Width > 720 && temp.Width <= 1080)
                            return 64;
                        else
                            return 72;
                    }
                    else
                    {
                        if (temp.Height <= 360)
                            return 16;
                        else if (temp.Height > 360 && temp.Height <= 480)
                            return 24;
                        else if (temp.Height > 480 && temp.Height <= 720)
                            return 32;
                        else if (temp.Height > 720 && temp.Height <= 1080)
                            return 48;
                        else
                            return 64;
                    }
                }
                catch { }
                return 32;
            }
        }
    }
}